package retu;

import leave.LeaveStudent;
import leave.StudentList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(StudentList studentList) {
        System.out.print("请输入该同学的姓名:>");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = studentList.getUseSize();
        boolean flag = true;
        for (int i = 0; i <size ; i++) {
            LeaveStudent leaveStudent = studentList.getLeaveStudents(i);
            if (name.equals(leaveStudent.getName())) {
                if (flag == leaveStudent.isLeave()) {
                    System.out.println("你已返校!");
                    return;
                }else {
                    leaveStudent.setLeave(false);
                    System.out.println("返校设置成功!");
                    return;
                }

            }
            System.out.println("没有此同学!");
        }
    }
}
